#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int numberOfArithmeticSlices(vector<int>& nums) {
        int n = nums.size();
        vector<vector<int>> dp(n, vector(n, 0));
        unordered_map<long long, vector<int>> hash;
        hash[nums[0]].push_back(0);
        int ret = 0;
        for (int i = 1;i < n;i++)
        {
            for (int j = i + 1;j < n;j++)
            {
                long long a = (long long)2 * nums[i] - nums[j];
                if (hash.count(a))
                {
                    for (auto e : hash[a])
                    {
                        dp[i][j] += dp[e][i] + 1;
                    }
                }
                ret += dp[i][j];
            }
            hash[nums[i]].push_back(i);
        }
        return ret;
    }
};